package com.caifu.controller.baseData;


import com.caifu.controller.AbstractController;
import com.caifu.pojo.SysUser;
import com.caifu.pojo.YlBuilding;
import com.caifu.service.IBuildingService;
import com.caifu.util.ImageFileUpload;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
* 
* 功能描述：楼苑管理
*
* @Author  GZ
* @Date   2020/11/5 15:47
*/
@Controller
@RequestMapping("/baseData/building")
public class BuildingController extends AbstractController {

    @Autowired
    private IBuildingService buildingService;

    /**
    * 
    * 功能描述：楼苑列表
    *
    * @Author  GZ
    * @Date   2020/11/5 15:48
    */
    @RequestMapping("buildingList")
    public String buildingList(){

        return "baseData/buildingList";
    }
    /**
    * 
    * 功能描述：分页查询楼苑信息列表
    *
    * @Author  GZ
    * @Date   2020/11/5 15:50
    */
    @RequestMapping("pagedQueryBuildingInfo")
    @ResponseBody
    public JSONObject pagedQueryBuildingInfo(){
        try {
            SysUser user = getUser();
            return buildingService.pagedQueryBuildingInfo(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
    * 
    * 功能描述：保存楼苑信息
    *
    * @Author  GZ
    * @Date   2020/11/5 15:52
    */
    @RequestMapping("saveBuildingInfo")
    @ResponseBody
    public JSONObject saveBuildingInfo(YlBuilding building, MultipartFile file){
        SysUser user = getUser();
        try {
            //图片上传
            if(null!=file&&StringUtils.isNotBlank(file.getOriginalFilename())){
                String imagePath = ImageFileUpload.imgFileUpload(file,"building",300);
                building.setBuildingImg(imagePath);
            }
            return buildingService.saveBuildingInfo(building,user);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
    * 
    * 功能描述：查询楼苑信息详情
    *
    * @Author  GZ
    * @Date   2020/11/6 15:35
    */
    @RequestMapping("queryBuildingInfoDetail")
    @ResponseBody
    public JSONObject queryBuildingInfoDetail(String buildingNo){
        try {
            return buildingService.queryBuildingDetail(buildingNo);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
    * 
    * 功能描述：更新楼苑信息
    *
    * @Author  GZ
    * @Date   2020/11/6 16:48
    */
    @RequestMapping("updateBuildingInfo")
    @ResponseBody
    public JSONObject updateBuildingInfo(YlBuilding building, MultipartFile file){
        try {
            //图片上传
            if(null!=file&&StringUtils.isNotBlank(file.getOriginalFilename())){
                String imagePath = ImageFileUpload.imgFileUpload(file,"building",300);
                building.setBuildingImg(imagePath);
            }
            return buildingService.saveBuildingUpdateInfo(building);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
    * 
    * 功能描述：删除楼苑信息
    *
    * @Author  GZ
    * @Date   2020/11/6 18:15
    */
    @RequestMapping("deleteBuildingInfo")
    @ResponseBody
    public JSONObject deleteBuildingInfo(String buildingNo){
        try {
            return buildingService.deleteBuildingInfo(buildingNo);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}
